<div class="layuimini-container">
    <form id="app-form" class="layui-form layuimini-form">

        <div id="regionTest"></div>
        <!--<div style="margin-left: 15px;">-->
            <!--您点击的地域是：<span id="click"></span></br>-->
            <!--提交的数据：<span id="all"></span>-->
        <!--</div>-->

        <div class="layui-form-item text-center">
            <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="quit()" >确认</button>
        </div>
    </form>
</div>
<script>

    require(['easy-admin'], function (ea) {

        layui.config({
            version: false
        }).extend({
            regionCheckBox: '{/}/static/plugs/lay-module/region-check-box/regionCheckBox' // {/}的意思即代表采用自有路径，即不跟随 base 路径
        })


        ea.request.get({
            url:'/manage/common/getMapData',
        }, function (res) {

            // console.log(res.data.data);
            //成功
            layui.use(['regionCheckBox'], function(){
                var regionCheckBox = layui.regionCheckBox;

               var value =  '{$data.value}';
               var deflut = [];
               if(value)deflut = value.split(",");
               console.log(value);
                //执行实例
                regionCheckBox.render({
                    elem: '#regionTest',
                    name: 'region', //input name
                     value: deflut, //赋初始值
                    data:res.data.data, //input name
                    width: '100%', //默认550px
                    border: true, //默认true
                    ready: function(){ //初始化完成时执行
                        // $('#all').html(this.name + '=' + getAllChecked());
                    },
                    change: function(result){ //点击复选框时执行
                        // $('#click').html(result.value);
                        // $('#all').html(this.name + '=' + getAllChecked());

                        parent.$("input[name='{$data.input_name}").val(getAllChecked());

                    }
                });

            })
        }, function (res) {
            //失败

        }, function (that) {
            //异常

        });


    });


    function getAllChecked(){
        var all = '';
        $("input:checkbox[name='region']:checked").each(function(){
                  var data = $(this).val();
                  // var index=data.indexOf("-");
                  // if(index!=-1)data = data.substring(index+1);
            all += data + ',';
        });
        return all.substring(0, all.length-1);
    }

    // layui.config({
    //     version: true
    // }).extend({
    //     regionCheckBox: '{/}/static/plugs/lay-module/region-check-box/regionCheckBox' // {/}的意思即代表采用自有路径，即不跟随 base 路径
    // })

  function quit() {
      var index1 = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
      parent.layer.close(index1); //再执行关闭
  }

</script>